import { createBrowserRouter } from "react-router-dom";

import Layout from "@/pages/Layout";
import Login from "@/pages/Login";
import { AuthRoute } from "@/components/AuthRoute";

import Home from "@/pages/Home";
import Article from "@/pages/Article";
import Publish from "@/pages/Publish";


const router = createBrowserRouter([
    {
        path: '/',
        // element: <Layout />
        // AuthRoute作用：有token正常跳转，没有则跳转到登录页面
        element: <AuthRoute><Layout /></AuthRoute>,
        children: [
            {
                // path: 'home', 默认打开home，去掉path，再设置index为true
                index: true,
                element: <Home />
            },
            {
                path: 'article',
                element: <Article />
            },
            {
                path: 'publish',
                element: <Publish />
            }
        ]
    },
    {
        path: '/login',
        element: <Login />
    }
])

export default router